package com.jiepos.mpos.core.intercept;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @ClassName: AppInterceptor
 * @Description: APP接口服务拦截器
 * @author 孙永
 * @date 2018年1月11日 上午10:30:43
 */
@Component
public class AppInterceptor extends HandlerInterceptorAdapter{
	
	/** GET请求方法*/
	private static final String METHOD_GET = "GET";
	
	private static Logger logger = LoggerFactory.getLogger(AppInterceptor.class);
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		logger.info("APP服务拦截器，请求路径：{}，请求方式：{}", request.getRequestURI(), request.getMethod());
		if(METHOD_GET.equals(request.getMethod())){
			response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
			return false;
		}
		return true;
	}
	
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
	}
	
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
	}
	
	@Override
	public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	}

}
